import type { VxeGlobalRendererHandles } from "vxe-pc-ui"
import { BSDataTypeEnum } from "@@/constants/other-keys"
import { ElInput } from "element-plus"
import { VxeUI } from "vxe-pc-ui"
import EnumValueDownModal from "./EnumValueDownModal.vue"
import TypingValueDownModal from "./TypingValueDownModal.vue"

// 创建一个复杂的组合渲染
VxeUI.renderer.add("TypingValueDownModal", {
  tableAutoFocus: "input",
  renderTableDefault(renderOpts, params) {
    const { row, column } = params

    if (row.field) {
      row.type = row.field && row.field.type
      row.recordType = row.field && row.field.recordType
    }

    let garams: VxeGlobalRendererHandles.RenderTableEditParams = renderOpts.abs
    let renderInner
    // 这是正常情况
    if (garams.row.field) {
      row.typeId = garams.row.field.typeId
      row.code = garams.row.field.code

      renderInner = <ElInput v-model={row[column.field]} />
      if (garams.row.field.type === BSDataTypeEnum.Base) {
        renderInner = <ElInput v-model={row[column.field]} />
      }
      if (garams.row.field.type === BSDataTypeEnum.Enum) {
        // ……务必设置，便于枚举值选择统一处理
        row.typeId = garams.row.field.typeId
        row.typeCode = garams.row.field.typeCode
        renderInner = <EnumValueDownModal params={params} renderOpts={renderOpts} />
      }
      if (garams.row.field.type === BSDataTypeEnum.Class) {
        // ……务必设置，便于枚举值选择统一处理
        row.typeId = garams.row.field.typeId
        row.typeCode = garams.row.field.typeCode
        renderInner = <TypingValueDownModal params={params} renderOpts={renderOpts} />
      }
    } else {
      let row = garams.row; let column = garams.column
      renderInner = <ElInput v-model={row[column.field]} />
      if (garams.row.type === BSDataTypeEnum.Base) {
        renderInner = <ElInput v-model={row[column.field]} />
      }
      if (garams.row.type === BSDataTypeEnum.Enum) {
        // ……务必设置，便于枚举值选择统一处理
        renderInner = <EnumValueDownModal params={garams} renderOpts={renderOpts} />
      }
      if (garams.row.type === BSDataTypeEnum.Class) {
        // ……务必设置，便于枚举值选择统一处理
        row.typeId = garams.row.typeId
        row.typeCode = garams.row.typeCode
        renderInner = <TypingValueDownModal params={params} renderOpts={renderOpts} />
      }
    }
    return [
      renderInner
    ]
  }
})
